package com.tjvib;

import android.app.AlertDialog;
import android.app.Application;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;

import com.chad.library.BuildConfig;
import com.tjvib.bean.SensorBean;
import com.tjvib.util.LogUtil;
import com.tjvib.util.Manager.AppManager;
import com.tjvib.util.ToastUtil;
import com.tjvib.view.dialog.HintDialog;
import com.tjvib.widget.NeverCrash;

public class TJVIBAPP extends Application {

    private static TJVIBAPP application;
    private static Context context;

    @Override
    public void onCreate() {
        super.onCreate();

        //在Application创建时,读取Application
        application = this;
        context = getApplicationContext();

        ToastUtil.init(this);

//        NeverCrash.getInstance()
//                .setDebugMode(BuildConfig.DEBUG)
//                .setMainCrashHandler((t, e) -> {
//                    LogUtil.e( "主线程异常");
//                    ToastUtil.show("主线程出现异常，日志位于Android\\data\\com.tjvib\\files\\logs");
//                    AppManager.getInstance().finishActivity();
////                    Intent i = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
////                    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
////                    context.startActivity(i);
//                })
//                .setUncaughtCrashHandler((t, e) -> {
//                    LogUtil.e("子线程异常");
//                    ToastUtil.show("子线程出现异常，日志位于Android\\data\\com.tjvib\\files\\logs");
//                    AppManager.getInstance().finishActivity();
////                    Intent i = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
////                    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
////                    context.startActivity(i);
//                })
//                .register(this);
    }

    @Override
    public void onTerminate() {
        super.onTerminate();
    }


    /**
     * 返回application
     **/
    public static TJVIBAPP getApplication() {
        return application;
    }

    /**
     * 返回context
     **/
    public static Context getContext() {
        return context;
    }
}
